/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.userautentification.dao;

import java.util.ArrayList;
import java.util.HashSet;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.userautentification.entities.Persona;
import com.userautentification.entities.Phone;
import com.userautentification.entities.Role;

public class Main {
    
	public static void main(String[] args) {

		ApplicationContext context = new ClassPathXmlApplicationContext(
				"/beans.xml");

		RoleDao roleDao = (RoleDao) context.getBean("roleDao");
		PersonaDao personaDao = (PersonaDao) context.getBean("personaDao");

		// Creo y guardo un rol
		Role role = new Role();
		role.setDescription("role1");
		role = roleDao.save(role);

		// role = roleDao.findById(role.getId());
		System.out.println("--->Role No: " + role.getId());
		System.out.println("--->Descripcion: " + role.getDescription());

		// roleDao.remove(role.getId());
		// obtengo todos los roles de la BD
		for (Role role2 : roleDao.getAll()) {
			System.out.println("--->Role No: " + role2.getId());
			System.out.println("--->Descripcion: " + role2.getDescription());
		}

		// Creo una persona
		Persona persona = new Persona();
		persona.setEmail("hola@hotmail.com");
		persona.setName("Maria");
		persona.setLastName("perez");
		persona.setPhone(new HashSet<Phone>());

		Phone phone = new Phone();
		phone.setNumber("21212");
		phone.setType("mobile");

		Phone phone2 = new Phone();
		phone2.setNumber("421212");
		phone2.setType("home");
		persona.getPhone().add(phone2);
		persona.getPhone().add(phone);
		
		persona = personaDao.save(persona);
		
		//Persona personaObtenida = personaDao.get(persona.getId());
		
		System.out.println(persona.toString());
		for (Phone phone3 : persona.getPhone()) {
			System.out.println(" Phone number: " + phone3.getNumber());	
		}
		

	}
        
    
    
    }
    